@extends("layouts.app",['categories'=>get_categoires_all($topic->category_id)])

@section('title','帖子编辑 - '.$topic->title)

@section('editor_css')
    <link rel="stylesheet" type="text/css" href="{{asset('css/simditor.css')}}"
@endsection



@section('content')
    <div class="row">


        <div class="col-md-8 offset-md-2">

            <div class="card">
                <div class="card-header">
                    <h5 class="pt-2 text-center"><i class="fa-solid fa-user-pen"></i>
                        发布帖子</h5>
                </div>
                <div class="card-body">
                    <form action="{{route('topics.update',$topic->id)}}" method="post" >
                        @csrf
                        {{method_field('PUT')}}
                        @include('utils._errors')
                        <div class="mb-3">
                            <label for="title" class="form-label">标题</label>
                            <input type="text" name="title" class="form-control" id="title" value="{{old('title',$topic->title)}}" placeholder="请输入标题">
                        </div>

                        <div class="mb-3">
                            <label for="category_id" class="form-label">分类</label>
                            <select name="category_id" class="form-select" id="category_id" aria-label="Default select example">
                                <option >请选择分类</option>
                                @foreach(get_categoires_all() as $category)
                                    <option value="{{$category->id}}"
                                        @if($category->id == $topic->category_id)
                                                selected
                                        @endif

                                    >{{$category->name}}</option>
                                @endforeach
                            </select>
                        </div>

                        {{--富文本--}}
                        <div class="mb-3">
                            <label for="editor" class="form-label">内容</label>
                            <textarea placeholder="写点儿什么吧" class="form-control" id="editor" name="content" rows="3">{{$topic->content}}</textarea>
                        </div>


                        <div class="mb-3 text-center">
                            <button type="submit" class="btn btn-primary">
                                提交
                            </button>
                        </div>

                    </form>
                </div>

            </div>


        </div>


    </div>


@stop

@section('editor_js')
    <script type="text/javascript" src="{{asset('js/module.js')}}"></script>
    <script type="text/javascript" src="{{asset('js/hotkeys.js')}}"></script>
    <script type="text/javascript" src="{{asset('js/uploader.js')}}"></script>
    <script type="text/javascript" src="{{asset('js/simditor.js')}}"></script>
    <script>
        $(document).ready(function (){
            let editor = new Simditor({
                textarea:$('#editor'),
                upload:{
                    url: "{{route('topics.imageUpload')}}",
                    params: {
                        _token: '{{csrf_token()}}',
                    },
                    fileKey: 'upload_file',
                    connectionCount: 5,
                    leaveConfirm: '图片上传未完成，确定要离开？',
                    pasteImage: false
                }
            });
        });
    </script>
@endsection
